package com.demo;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class DemoController {

	@RequestMapping(value = "/{hello}", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public void view(@PathVariable("hello") String hello,
			HttpServletResponse response,HttpServletRequest  request) {
		// model.addAttribute("v", attributeValue);
		response.addHeader("Content-Type", "text/html;charset=utf-8");
		response.setCharacterEncoding("UTF-8");
		try {
			String addr = request.getLocalAddr();
			response.getWriter()
					.println(
							String.format(
									"<html><head><title>demo</title></head><body><h2>Hello %s v9 ,"+addr+"</h2></body></html>",
									hello));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
